unit SUTarget;

interface
  type
    PTarget = class
      private
        class var _Instance : PTarget;
        constructor Create;overload;
        function SinIsActive: Boolean;
    function SinGetLastTargetID: Cardinal;
      public
        class function GetInstance():PTarget;



        function TargetTo(ObjectID : Cardinal;DoWait:Boolean = False):Boolean; overload;
        function TargetTo(X, Y : Word; Z : ShortInt;DoWait:Boolean = False):Boolean; overload;
        function TargetTo(TileModel,X,Y : Word; Z : ShortInt;DoWait:Boolean = False):Boolean; overload;
        function TargetTo(ObjType:Word;UseGround:Boolean = False):Boolean; overload;

        function TargetSelf():Boolean;
        function TargetLast():Boolean;

        function CancelTarget(DoWait:Boolean = False):Boolean;
        function WaitForTarget(MaxWaitTimeInMS:Cardinal):Boolean;

        property Active : Boolean read SinIsActive;

        property LastTargetID : Cardinal read SinGetLastTargetID;

    end;

implementation
  uses
    SUStealth;

{ PTarget }

function PTarget.CancelTarget(DoWait:Boolean = False):Boolean;
begin
  Result := True;
  if(not Active)then exit;
  if(DoWait)then
  begin
    Script.Target.CancelWaitTarget;
  end else begin
    Script.Target.CancelTarget;
  end;
  Result := not Active;
end;

constructor PTarget.Create;
begin
  //Unused
end;

class function PTarget.GetInstance: PTarget;
begin
  if not Assigned(_Instance) then _Instance := PTarget.Create;
  Result := _Instance;
end;

function PTarget.SinGetLastTargetID: Cardinal;
begin
  Result := Script.Target.TargetPresent;
end;

function PTarget.SinIsActive: Boolean;
begin
  Result := Script.Target.TargetID;
end;

function PTarget.TargetTo(X, Y: Word; Z: ShortInt; DoWait: Boolean):Boolean;
begin
  Result := False;
  if(not Active)then exit;
  Result := True;
  if(DoWait)then
  begin
    Script.Target.WaitTargetXYZ(X,Y,Z);
  end else begin
    Script.Target.TargetToXYZ(X,Y,Z);
  end;
end;

function PTarget.TargetTo(ObjectID: Cardinal; DoWait: Boolean):Boolean;
begin
  Result := False;
  if(not Active)then exit;
  Result := True;
  if(DoWait)then
  begin
    Script.Target.WaitTargetObject(ObjectID);
  end else begin
    Script.Target.TargetToObject(ObjectID);
  end;
end;

function PTarget.TargetTo(TileModel, X, Y: Word; Z: ShortInt; DoWait: Boolean):Boolean;
begin
  Result := False;
  if(not Active)then exit;
  Result := True;
  if(DoWait)then
  begin
    Script.Target.WaitTargetTile(TileModel,X,Y,Z);
  end else begin
    Script.Target.TargetToTile(TileModel,X,Y,Z);
  end;
end;

function PTarget.WaitForTarget(MaxWaitTimeInMS: Cardinal): Boolean;
begin
  Result := Script.Target.WaitForTarget(MaxWaitTimeInMS);
end;

function PTarget.TargetLast():Boolean;
begin
  Result := False;
  if(not Active)then exit;
  Result := True;
  Script.Target.WaitTargetLast;
end;

function PTarget.TargetSelf():Boolean;
begin
  Result := False;
  if(not Active)then exit;
  Result := True;
  Script.Target.WaitTargetSelf;
end;

function PTarget.TargetTo(ObjType: Word; UseGround: Boolean):Boolean;
begin
  Result := False;
  if(not Active)then exit;
  Result := True;
  if(UseGround)then
  begin
    Script.Target.WaitTargetType(ObjType);
  end else begin
    Script.Target.WaitTargetGround(ObjType);
  end;
end;

end.
